<?php
/**
 * Created by PhpStorm.
 * User: trisatria
 * Date: 1/7/14
 * Time: 3:50 PM
 */

namespace Admin\Form;
use Velacolib\Utility\Utility;
use Zend\Form\Form;
use Admin\Module;
use Zend\InputFilter;
use Zend\Form\Element;
use Zend\Captcha;
use Zend\Captcha\Image;


class AdminTopicForm extends Form{
    public function __construct($name = null)
    {

        // we want to ignore the name passed
        parent::__construct('AdminTopic');
        $this->setAttribute('method', 'post');
        $this->setAttribute('class', 'form-horizontal');
        $this->setAttribute('enctype', 'multipart/form-data');

        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type'  => 'hidden',

            ),
        ));

        $this->add(array(
            'name' => 'create_date',
            'attributes' => array(
                'type'  => 'hidden',

            ),
        ));

        $this->add(array(
            'name' => 'user_id',
            'attributes' => array(
                'type'  => 'hidden',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));
        $this->add(array(
            'name' => 'title',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));



        $this->add(array(
            'name' => 'price',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));



        $this->add(array(
            'name' => 'short_description',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));


        $this->add(array(
            'name' => 'full_description',
            'attributes' => array(
                'type'  => 'textarea',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));

        $this->add(array(
            'name' => 'expire_date',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead datepicker'
            ),

        ));
        $this->add(array(
            'type' => 'Zend\Form\Element\Radio',
            'class'=>'radio',
            'name' => 'topic_type',
             'options' => array(
            'value_options' => array(
            '0' => 'Cần bán',
            '1' => 'Cần mua',
        ),
    )
     ));


              $product_loc = array();
              $product_loc = Utility::getLocationArray()  ;
        foreach($product_loc as $key => $l){
            $value_option[$key] = $l;
            }


        $this->add(array(
            'type' => 'Zend\Form\Element\Select',
            'name' => 'topic_location',
             'options' => array(
        'value_options' => $value_option,
        )
         ));
/*
        $captcha = new Captcha\Image();
        $captcha->setFont('./data/fonts/Gabriola.ttf');
        $captcha->setImgDir('./public/captcha');
        $captcha->setImgUrl('/captcha');
        $this->add(array(
            'type' => 'Zend\Form\Element\Captcha',
            'name' => 'captcha',
            'options' => array(
                'captcha' => $captcha,
            ),
        ));
*/

        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id' => 'submitbutton',
                'class' => 'btn btn-primary span3 typeahead'
            ),
        ));



        $file_img = new Element\File('images');
        $file_img->setAttribute('class', 'input-xlarge focused span6 typeahead');
        $this->add($file_img);


        $select_show_price = new Element\Select('show_price');
        $select_show_price->setAttribute('class','input-xlarge focused span6 typeahead');
        $select_show_price->setAttribute('id','selU52');
        $select_show_price->setValueOptions(Module::getTopicShowPrice());



        $select_status = new Element\Select('status');
        $select_status->setAttribute('class','input-xlarge focused span6 typeahead');
        $select_status->setAttribute('id','selU51');
        $select_status->setValueOptions(Module::getUserStatusName());

        $cat_list_select = array();
        $cat_list = Utility::getTopicCat()->getAll();
        $cat_list_select[0] = 'No Category Select';
        foreach($cat_list as $cat){
            $cat_list_select[$cat->id] = $cat->title ;
        }


        $select_us_type = new Element\Select('cat_id');
        $select_us_type->setAttribute('class','input-xlarge focused span6 typeahead');
        $select_us_type->setAttribute('id','selU50');
        $select_us_type->setValueOptions($cat_list_select);




        $is_brandnew = new Element\Select('is_brandnew');
        $is_brandnew->setAttribute('class','input-xlarge focused span6 typeahead');
        $is_brandnew->setAttribute('id','selU50');
        $is_brandnew->setValueOptions(array('1'=>'Mới', '0'=>'Cũ'));

        $this->add(array(
            'name' => 'thumb',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));

        $this->add(array(
            'name' => 'up_date',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));

        $this->add(array(
            'name' => 'slug',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));


        $this->add(array(
            'name' => 'viewed',
            'attributes' => array(
                'type'  => 'text',
                'class'=>'input-xlarge focused span6 typeahead'
            ),

        ));


        $select_is_public = new Element\Select('is_public');
        $select_is_public->setAttribute('class','input-xlarge focused span6 typeahead');
        $select_is_public->setAttribute('id','selU50');
        $select_is_public->setValueOptions(array('yes'=>'Có', 'no'=>'Không'));

        $this->add($is_brandnew);
        $this->add($select_is_public);
        $this->add($select_status);
        $this->add($select_us_type);
        $this->add($select_show_price);

        $this->addInputFilter();
    }

    public function addInputFilter()
    {

//        $inputFilter = new InputFilter\InputFilter();
//        // File Input
//        $fileInput = new InputFilter\FileInput('images');
//        $fileInput->setRequired(false);
//
//        $fileInput->getFilterChain()->attachByName( 'filerenameupload',
//            array(
//                'target'    => './public/img/upload/avatar.png',
//                'randomize' => true,
//                'use_upload_name' =>true
//            )
//        );
//
//
//        $inputFilter->add($fileInput);
//
//        $this->setInputFilter($inputFilter);

//        echo '<pre>';
//        print_r($fileInput);
//        echo '</pre>';
    }
}